package day52.basic.service.impl;

import day52.basic.util.PageList;
import day52.basic.mapper.BaseMapper;
import day52.basic.query.BaseQuery;
import day52.basic.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public T findOne(Long id) {
        return baseMapper.findOne(id);
    }

    @Override
    @Transactional
    public void add(T t) {
        baseMapper.add(t);

    }

    @Override
    @Transactional
    public void delete(Long id) {
        baseMapper.delete(id);

    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);

    }

    @Override
    public PageList<T> pageQuery(BaseQuery baseQuery) {

        return new PageList<>(baseMapper.count(baseQuery),baseMapper.pageQuery(baseQuery));
    }

    @Override
    @Transactional
    public void patchDelete(List<Long> ids) {
        baseMapper.patchDelete(ids);

    }
}
